package com.hong.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        boolean createTime = metaObject.hasSetter("createTime");
        if (createTime){
            setFieldValByName("createTime",new Date(),metaObject);
        }
        boolean modifyTime = metaObject.hasSetter("modifyTime");
        if (modifyTime){
            setFieldValByName("modifyTime",new Date(),metaObject);

        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        boolean modifyTime = metaObject.hasSetter("modifyTime");
        if (modifyTime){
            setFieldValByName("modifyTime",new Date(),metaObject);
        }
    }


}
